#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ev++.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

#include <iostream>
#include <fstream>
#include <string>
#include <map>

#include <json/json.h>
#include "jpacket.h"
#include "libfun.h"
#include "match_server.h"

class TcpClient;
class Player;
class Room;


class NetworkListen
{

public:
	std::map<int, TcpClient*> 		_fd_clients;

private:
	ev_io _ev_accept;
	int _fd;

public:
	NetworkListen() {};
	virtual ~NetworkListen() {};
	virtual int dispatch(TcpClient *tcpclient) = 0;

	bool CancelFd(int fd);
protected:
	int init_accept(struct ev_loop *loop, int port);
	virtual TcpClient* NewConnect(int fd) = 0;
	static void accept_cb(struct ev_loop *loop, struct ev_io *w, int revents);
};